package com.youhp.spire.xls.demo.Worksheets;

import com.spire.xls.*;

import java.util.EnumSet;

public class ProtectWorksheet {
    public static void main(String[] args) {
        String inputFile = "data/ProtectWorksheet.xlsx";
        String outputFile = "output/ProtectWorksheet_out.xlsx";

        //Create a workbook and load a file
        Workbook workbook = new Workbook();
        workbook.loadFromFile(inputFile);

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Protect this sheet with a password.
        sheet.protect("TestPassword", EnumSet.of(SheetProtectionType.All));

        //Save the Excel file
        workbook.saveToFile(outputFile,ExcelVersion.Version2013);
    }
}
